#pragma once

#include <iostream>
#include <string>
#include <cerrno>
#include <cstring>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

using namespace std;

#define Mode 0666
#define Path "./test"


class Fifo
{
    public:
    Fifo(const string &path)
    : _path(path)
    {
       umask(0);
        
        //命名管道
       int n=mkfifo(_path.c_str(),Mode);

       if(n==0)
       {
        cout<<"创建管道成功"<<endl;
       }
       else
       {
       cerr << "mkfifo failed, errno: " << errno << ", errstring: " << strerror(errno) << endl;
       }


    }

  ~Fifo()
  {
    //删除指定路径的文件或目录
     int n= unlink(_path.c_str());
     if(n==0)
     {
       cout<<"删除成功"<<endl;
     }
     else
     {
     cerr << "unlink failed, errno: " << errno << ", errstring: " << strerror(errno) << endl;
     }

  }

    private:
    string _path;//文件路径+文件名
};